package eight;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


public class EightDriver {

    public static void main(String[] args) throws Exception {
//        if (args.length != 2) {
//            System.err.println("Usage: YearFilterJob <input path> <output path>");
//            System.exit(-1);
//        }

        Configuration conf = new Configuration();
        conf.set("fs.defaultFS", "hdfs://192.168.43.129:8020");
        Job job = Job.getInstance(conf, "Year Filter");
        job.setJarByClass(EightDriver.class);
        job.setMapperClass(EigntMapper.class);
        job.setReducerClass(EightReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        FileInputFormat.addInputPath(job, new Path("/input/qingdao/kaifangmulu.csv"));
        String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        String dynamicOutputPath = "/output/output_" + currentTime; // 直接指定HDFS上的output目录，并添加时间戳
        FileOutputFormat.setOutputPath(job, new Path(dynamicOutputPath)); // 设置动态HDFS输出路径

        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}